import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

class Read {
    StringTokenizer st=new StringTokenizer("");
    BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
    public String next() throws IOException {
        while (!st.hasMoreTokens()){
            st=new StringTokenizer(bf.readLine());
        }
        return st.nextToken();
    }
    public String nextLine() throws IOException {
        return bf.readLine();
    }
    public int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
    public long nextLong() throws IOException {
        return Long.parseLong(next());
    }
}
public class Main {
    public static Read in=new Read();
    public static PrintWriter out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    public static void main1(String[] args) throws IOException {
        int t= in.nextInt();
        while (t-->0) {
            int n= in.nextInt(),k= in.nextInt();
            char[] arr=in.next().toCharArray();
            int ret=0;
            for (int i = 0; i < n; i++) {
                if(i>=2&&arr[i]=='W'&&arr[i-1]=='W'&&arr[i-2]=='W'){
                    ret+=k;
                } else if (arr[i]=='W') {
                    ret++;
                }
                else {
                    ret--;
                }
            }
            System.out.println(ret);
        }
    }
    public int maxLength (int[] arr) {
        int n=arr.length;
        int left=0,right=0,max=0;
        int[] hash=new int[100001];
        while (right<n){
            if(hash[arr[right]]==0){
                hash[arr[right]]++;
            }
           else {
                while (hash[arr[right]] != 0&&left<=right) {
                    hash[arr[left]]--;
                    left++;
                }
                hash[arr[right]]++;
            }
           max=Math.max(max,right-left+1);
           right++;
        }
        return max;
    }

    public static void main2(String[] args) throws IOException {
        int n= in.nextInt();
        char[] s=in.next().toCharArray();
        char maxChar='0';
        int maxCount=0;
        int[] hash=new int[26];
        for (int i = 0; i < n; i++) {
            char a=s[i];
            if(++hash[a-'a']>maxCount){
                maxChar=a;
                maxCount=hash[a-'a'];
            }
        }
        if(maxCount>n+1/2) System.out.println("no");
        else {
            System.out.println("yes");
            char[] ret=new char[n];
            int i=0;
            while (maxCount-->0){
                ret[i]=maxChar;
                i+=2;
            }
            for (int j = 0; j < 26; j++) {
                if(hash[j]!=0&&(char) (j+'a')!=maxChar){
                    while (hash[j]-->0){
                        if(i>n) i=1;
                        ret[i]=(char)(j+'a');
                        i+=2;
                    }
                }
            }
            for (int j = 0; j < n; j++) {
                System.out.println(ret[j]);
            }
        }
    }

    public static void main3(String[] args) throws IOException {
        char[] s1= in.next().toCharArray();
        char[] s2= in.next().toCharArray();
        int[] hash =new int[26];
        int n=s1.length,m=s2.length;
        if(n<m) System.out.println("No");
        else {
            for (int i = 0; i < n; i++) {
                hash[s1[i]-'A']++;
            }
            int k=0;
            while (k<m) {
                if(hash[s2[k]-'A']>0){
                    hash[s2[k]-'A']--;
                    k++;
                }
                else {
                    System.out.println("No");
                    break;
                }
            }
            if(k==m) System.out.println("Yes");
        }
    }

    public static void main4(String[] args) throws IOException {
        int n= in.nextInt();
        int[] nums=new int[3*n];
        int ret=0;
        for (int i = 0; i < 3*n; i++) {
            nums[i]=in.nextInt();
        }
        Arrays.sort(nums);
        int k=3*n-2;
        for(int i=0;i<n;i++){
            ret+=nums[k];
            k-=2;
        }
        System.out.println(ret);
    }

    public static void main(String[] args) throws IOException {
        int n= in.nextInt();
        int[] nums=new int[n];
        int[] hash=new int[10010];
        for (int i = 0; i < n; i++) {
            nums[i]= in.nextInt();
            hash[nums[i]]++;
        }
        int ret=0;
        int[] f=new int[10010],g=new int[10010];
        for (int i = 1; i < 10010; i++) {
            f[i]=g[i-1]+i*hash[i];
            g[i]=Math.max(g[i-1],f[i-1]);
            ret=Math.max(f[i],g[i]);
        }
        System.out.println(ret);
    }
}